let rec insert cmp e = function
   | [] -> [e]
   | h :: t as l -> if cmp e h <= 0 then e :: l else h :: insert cmp e t
;;
let rec sort cmp = function
   | [] -> []
   | h :: t -> insert cmp h (sort cmp t)
;;

let () = 
  let lst = sort compare [3; 1; 2] in
  List.iter (fun x -> Printf.printf "%d " x) lst;
  print_newline ()
;;